#include<iostream>
#include <string>
#include <queue>
using namespace std;

typedef struct node{
    char data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
typedef struct node *BTree;

void CreateBTree(BTree &BT,string str);
void PreOrder( BTree BT );
int trans( char n );
int count=0,flag1,num=0,len,index=0;

int main(){
	string str;
	BTree BT;
	cin>>str;
	len=str.length();
	CreateBTree(BT,str);
	
	if(index==1)
		cout<<"0";
	else{
		PreOrder( BT );
		//cout<<endl<<count<<" "<<num; 
		cout<<endl<<num*count;
	}
	return 0;
}

void CreateBTree(BTree &BT,string str){
	BTree T;
	int i=1,cnt=0;;
	queue<BTree>Tree;
	if(str[i]=='#'){
		index=1;
		BT=NULL;
	}
	else{
		BT=new BTNode;
		BT->data=str[i];
		BT->lchild=BT->rchild=NULL;
		Tree.push(BT);
	} 
	while(!Tree.empty()&&cnt<len&index!=1){
		cnt++;
		i++;
		T=Tree.front();
		Tree.pop();
		T->lchild=new BTNode;
		T->lchild->data=str[i];
		T->lchild->lchild=T->lchild->rchild=NULL;
		Tree.push(T->lchild);
		
		cnt++;
		i++;
		T->rchild=new BTNode;
		T->rchild->data=str[i];
		T->rchild->lchild=T->rchild->rchild=NULL;
		Tree.push(T->rchild);
	}
}

void PreOrder( BTree BT ){
	if(BT!=NULL){
		if( ( (!BT->lchild) && (!BT->rchild) )  ) {
			num+=trans(BT->data);
			cout<<endl<<BT->data;
			//cout<<endl<<count<<endl;        
		}
    	PreOrder(BT->lchild);  
    	PreOrder(BT->rchild);
	}    
} 

int trans( char n ){
	if(n=='1'){
		count++;
		return 1;
	}
	else if(n=='2'){
		count++;
		return 2;
	}
	else if(n=='3'){
		count++;
		return 3;
	}
	else if(n=='4'){
		count++;
		return 4;
	}
	else if(n=='5'){
		count++;
		return 5;
	}
	else if(n=='6'){
		count++;
		return 6;
	}
	else if(n=='7'){
		count++;
		return 7;
	}
	else if(n=='8'){
		count++;
		return 8;
	}
	else if(n=='9'){
		count++;
		return 9;
	}
	else if(n=='0'){
		count++;
		return 0;
	}
	else return 0;
}

